import 'package:base_lib/common/bloc/base_bloc.dart';
import 'package:base_lib/index.dart';
import 'package:doctor_login_lib/cache/userinfo_cache.dart';
import 'package:doctor_login_lib/login/entity/doctor_login_entity.dart';
import 'package:doctor_prescribe_lib/repository/http.dart';
import 'package:rxdart/rxdart.dart';
import 'entity/diagnostic_result_list_entity.dart' as DiagnosticBean;

class DiagnosticSearchBloc extends BaseBloc {
  List<DiagnosticBean.Data> _list = [];
  PublishSubject<List<DiagnosticBean.Data>> listSubject = PublishSubject();

  @override
  void dispose() {
    listSubject?.close();
  }

  DoctorUser doctorUser;

  @override
  void initState() async {
    super.initState();
    doctorUser = await UserInfoCache.getInstance().get();
    getList();
  }

  getList({String keyStr = ''}) async {
    var result = await PrescribeHttp.getXPICD(doctorUser.orgID, keyStr: keyStr);
    if (result.isSuccess) {
      _list
        ..clear()
        ..addAll(result.data);
      listSubject.add(_list);
    } else {
      ToastUtil.error(result.error.msg);
    }
  }
}
